/*
 * @: 
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-10-18 21:56:45
 * @LastEditors: ziwei
 * @LastEditTime: 2021-10-18 22:21:55
 */

//actionCreator function add(){return {type:ADD}}
//dispatch store.dispatch
function bindActionCreator(actionCreator,dispatch){
    return function(...args){
        return dispatch(actionCreator.apply(this,args))
    }
    
}

/* actionCreators action的创建者 此处可以只传一个创建者 也就是一个函数 也可以穿一个对象*/
function bindActionCreators(actionCreators,dispatch){
    if(typeof actionCreators === 'function'){
        return bindActionCreator(actionCreators,dispatch)
    }
    const boundActionsCreators = {}
    for(const key in actionCreators){
        const actionCreator = actionCreators[key]
        boundActionsCreators[key] = bindActionCreator(actionCreator,dispatch)
    }
    return boundActionsCreators
}

export default bindActionCreators